<script>
let that
import {
	mapGetters,
	mapActions
} from 'vuex'
export default {
	globalData: {  
		time: '',
		image_svr:'',//图片前缀，用于nvue获取的
		GK_QSS_ONOFF:{//是否开启国科量子加解密
			email:true,//邮箱
		},
	},
	computed: {
		...mapGetters(['APPTheme','userInfo','api'])
	},
	onLaunch: function() {
		that=this
		getApp().globalData.image_svr=that.GLOBAL.image_svr
		console.log('App Launch');
		uni.$off('start_up_heartBeat')
		uni.$on('start_up_heartBeat',(res)=>{
			console.log('启动心跳');
			//心跳
			clearInterval(getApp().globalData.time)
			getApp().globalData.time=setInterval(()=>{
				//#ifndef H5
				that.heartBeat()
				//#endif
			},5000)
		})
	},
	onReady() {
		//设置主题颜色
		uni.$lizhao.setThemeColor(that.APPTheme)
	},
	onShow: function() {
		console.log('App Show');
		//心跳
		clearInterval(getApp().globalData.time)
		getApp().globalData.time=setInterval(()=>{
			//#ifndef H5
			that.heartBeat()
			//#endif
		},5000)
		// this.loginFn()
		//#ifdef APP-PLUS
		that.gkQSS();
		//#endif
	},
	onHide: function() {
		console.log('App Hide');
		clearInterval(getApp().globalData.time)
	},
	methods:{
		...mapActions(['set_userInfo','set_userToken']),
		//心跳机制
		heartBeat(){
			let id=''
			try{
				id=JSON.parse(that.userInfo).id
			}catch(e){
				//TODO handle the exception
			}
			that.GLOBAL.doGet(that.api.GLOBAL_rest_webSocket_chat_heartBeat,{id}).then(res=>{
				// console.log('websocket连接状态',res);
				if(res.data=='0'){
					that.$lizhao.lzwebSocket.lz_websoket(true);
				}
			})
		},
		
		loginFn(){
			let userInfo=uni.getStorageSync('userInfo_password_name')
			console.log('启动页userInfo',userInfo);
			that.GLOBAL.doPost(that.api.GLOBAL_login,userInfo).then(res=>{
				console.log(res.code);
				if(res.code=='200'){
					//存储userToken
					that.set_userToken(res.data.token)
					//存储用户信息
					that.set_userInfo(res.data)
					//获取国科量子参数
					//#ifdef APP-PLUS
					that.gkQSS();
					//#endif
				}else{}
			}).catch(error=>{
				console.log(error);
			})
		},
		//获取国科量子参数
		gkQSS(){
			let userInfo=uni.getStorageSync('userInfo_password_name')
			console.log('启动页获取国科量子参数');
			that.GLOBAL.doGet(that.api.GLOBAL_rest_chat_encryption_initKey,{keyIndex:userInfo.loginName}).then(res=>{
				if(res.code=='00'){
					let qss=res.data
					that.$lizhao.QSS.initQSS(qss.pubkey,qss.prvkey,qss.kek,qss.zmk)
				}
				
			});
		},
		
	}
};
</script>

<style lang="scss">
	/* #ifndef APP-PLUS-NVUE */
	@import "./static/iconfont/iconfont.css";
	@import "./static/css/common.scss";
	
	// //按下去的颜色配置及主题背景
	// .theme-dark{
	// 	//主题背景
	// 	.theme-bg{
	// 		background-color: #1e1e1e;
	// 	}
	// 	.theme-bg-auto{
	// 		background-color: #1e1e1e;
	// 	}
	// 	.theme-bg-auto2{
	// 		background-color: #343434;
	// 	}
	// 	//按下背景
	// 	.theme-bg-active:active{
	// 		background-color: $bg-active-dark!important;
	// 	}
	// 	// 底边线
	// 	.theme-border-bottom{
	// 		border-bottom: 0.1px solid #1e1e1e;
	// 	}
	// 	.theme-border-bottom-8{
	// 		border-bottom: 8px solid #1e1e1e;
	// 	}
	// 	.theme-border-bottom-auto{border-bottom: 0.1px solid #343434;}
	// 	.theme-border-bottom-after{position: relative;}
	// 	.theme-border-bottom-after::after{position: absolute;box-sizing: border-box;content: ' ';pointer-events: none;right: 0;
	// 		left: 0;top: 0;border-bottom: 1px solid #343434;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);}
	// 	//上边线
	// 	.theme-border-top{
	// 		border-top: 0.1px solid #1e1e1e;
	// 	}
		
	// 	.theme-border-top-8{
	// 		border-top: 8px solid #1e1e1e;
	// 	}
	// 	.theme-border-top-auto{
	// 		border-top: 0.1px solid #343434;
	// 	}
		
	// 	//左边线
	// 	.theme-border-left-auto{
	// 		border-left: 0.1px solid #343434;
	// 	}
	// }
	// .theme-light{
	// 	.theme-bg{
	// 		background-color: rgba($color: #f0f0f0, $alpha: 0.5);
	// 	}
	// 	.theme-bg-auto{
	// 		background-color: #a3a3a3;
	// 	}
	// 	.theme-bg-auto2{
	// 		background-color: #fff;
	// 	}
	// 	.theme-bg-active:active{
	// 		background-color: $bg-active-light!important;
	// 	}
	// 	.theme-border-bottom{
	// 		border-bottom: 0.1px solid #f0f0f0;
	// 	}
	// 	.theme-border-bottom-8{
	// 		border-bottom: 8px solid #f0f0f0;
	// 	}
	// 	.theme-border-bottom-auto{
	// 		border-bottom: 0.1px solid #dcdcdc;
	// 	}
	// 	.theme-border-bottom-after{position: relative;}
	// 	.theme-border-bottom-after::after{position: absolute;box-sizing: border-box;content: ' ';pointer-events: none;right: 0;
	// 		left: 0;top: 0;border-bottom: 1px solid #dcdcdc;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);}
	// 	.theme-border-top{
	// 		border-top: 0.1px solid #f0f0f0;
	// 	}
	// 	.theme-border-top-8{
	// 		border-top: 8px solid #f0f0f0;
	// 	}
	// 	.theme-border-top-auto{
	// 		border-top: 0.1px solid #dcdcdc;
	// 	}
	// 	//左边线
	// 	.theme-border-left-auto{
	// 		border-left: 0.1px solid #dcdcdc;
	// 	}
	// }
	/* #endif */
	
	
/* 解决头条小程序组件内引入字体不生效的问题 */
/* #ifdef MP-TOUTIAO */
@font-face {
	font-family: uniicons;
	src: url('/static/uni.ttf');
}
/* #endif */
</style>
